package com.effvi.taoke.interceptor;

import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
/**
 * 网站开放时段拦截器
 * @author kelvin.zhang
 *
 */
public class TimerInterceptor extends HandlerInterceptorAdapter {
	
	private static Logger logger = Logger.getLogger(TimerInterceptor.class);
	
	private int openingTime;
	private int closingTime;
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		Calendar cal = Calendar.getInstance();
		int hour = cal.get(Calendar.HOUR_OF_DAY);
		if( closingTime > hour && openingTime < hour){
			logger.debug("正在校验是否为网站工作时段!");
			return super.preHandle(request, response, handler);
		}else{
			logger.debug("非服务时段，暂停服务!");
			response.sendRedirect("/exceptions/UnsuportAdminService");
			return false;
		}
	}
	public int getOpeningTime() {
		return openingTime;
	}
	public void setOpeningTime(int openingTime) {
		this.openingTime = openingTime;
	}
	public int getClosingTime() {
		return closingTime;
	}
	public void setClosingTime(int closingTime) {
		this.closingTime = closingTime;
	}

}
